﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCDto.CRM.CustomerFollowUpRecord;
using BCService.CRM.CustomerFollowUpRecord;

namespace BCTMSRESTful.Controllers.Management.CRM.CustomerFollowUpRecord
{
    /// <summary>
    /// 客户跟进记录接口
    /// </summary>  
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class CustomerFollowUpRecordController : ManagementBaseController
    {
        #region var
        private ICustomerFollowUpRecordService cCustomerFollowUpRecordService;
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public CustomerFollowUpRecordController(ICustomerFollowUpRecordService ccCustomerFollowUpRecordService)
        {
            this.cCustomerFollowUpRecordService = ccCustomerFollowUpRecordService;
        }
        #endregion

        #region POST
        /// <summary>
        /// 创建客户跟进记录记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpPost]        
        [ProducesResponseType(typeof(CustomerFollowUpRecordRequestDto), 200)]
        public IActionResult Post([FromBody]CustomerFollowUpRecordRequestDto dto)
        {
            var a = this.cCustomerFollowUpRecordService.Insert(Admin, dto);

            return Ok(a); 
        }

        #endregion

        #region PUT
        /// <summary>
        /// 修改客户跟进记录记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpPut]        
        [ProducesResponseType(typeof(CustomerFollowUpRecordDto), 200)]
        public IActionResult Put([FromBody]CustomerFollowUpRecordDto dto)
        {
            var a = Ok(cCustomerFollowUpRecordService.Update(Admin,dto));
            return a;
        }
        #endregion

        #region delete
        /// <summary>
        /// 删除客户跟进记录记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{customer_follow_up_record_id}")]         
        public IActionResult Delete([FromRoute(Name = "customer_follow_up_record_id")]long id)
        {
            cCustomerFollowUpRecordService.Delete(id);

            return NoContent();
        }
        #endregion

        #region GetByID 
        /// <summary>
        /// 获取客户跟进记录记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpGet("{customer_follow_up_record_id}")]        
        [ProducesResponseType(typeof(CustomerFollowUpRecordDto), 200)]
        public IActionResult GetByID([FromRoute(Name = "customer_follow_up_record_id")]long ccID)
        {
            var a = Ok(cCustomerFollowUpRecordService.GetByID(ccID));
            return a;
        }
        #endregion

        #region GetList
        /// <summary>
        /// 获取全部客户跟进记录
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]        
        [ProducesResponseType(typeof(PageableList<CustomerFollowUpRecordDto>), 200)]
        public IActionResult GetList([FromQuery(Name = "index")]int? pageIndex = 1, [FromQuery(Name = "size")]int? pageSize = 10)
        { 
            var a = Ok(cCustomerFollowUpRecordService.GetList(Admin,pageIndex.Value,  pageSize.Value));
            return a;
        }
        #endregion

        #region GetLastRecord
        /// <summary>
        /// 获取指定客户ID的最新一条客户跟进记录
        /// </summary>
        /// <param name="ccID"></param>
        /// <returns></returns>
        [HttpGet("[action]/{customer_info_id}")]        
        [ProducesResponseType(typeof(CustomerFollowUpRecordDto), 200)]
        public IActionResult  GetLastRecord([FromRoute(Name = "customer_info_id")]long ccID)
        {
            return Ok(cCustomerFollowUpRecordService.GetLastRecord(ccID));
        }
        #endregion

        #region GetListByCustomer
        /// <summary>
        /// 分页获取指定客户客户跟进记录列表
        /// </summary>
        /// <param name="ccID"></param>
        /// <param name="ccPageNo"></param>
        /// <param name="ccPageSize"></param>
        /// <returns></returns>
        [HttpGet("[action]")]        
        [ProducesResponseType(typeof(PageableList<CustomerFollowUpRecordDto>), 200)]
        public IActionResult GetListCustomer( [FromQuery(Name = "customer_info_id")]long ccID,
                                                                  [FromQuery(Name ="index")]int? ccPageNo=1,
                                                                  [FromQuery(Name ="size")]int? ccPageSize=10)
        {

            if (ccPageNo.Value <= 0 || ccPageSize.Value > 100)
                return BadRequest("页码参数错误!"); 
            return Ok(cCustomerFollowUpRecordService.GetListByCustomer(ccID, ccPageNo.Value, ccPageSize.Value));
        }
        #endregion
    }
}
